# @Time : 2021/7/29 18:16 
# @Author : zhangyanjun
# @File : MobilePhoneValidator.py
# @Contact: 174563752@qq.com
# @Description:实现手机号码验证
import re
from django.core.validators import RegexValidator, _lazy_re_compile
from django.utils.deconstruct import deconstructible


@deconstructible
class MobilePhoneValidator(RegexValidator):
    # phone patterns
    phone_re = r'^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$'

    regex = _lazy_re_compile(phone_re, re.IGNORECASE)
    message = 'Enter a valid phone.'


validate_phone = MobilePhoneValidator()
